﻿using System.Windows;
using System.Windows.Input;
using WPFToolBarExample.Helper;
using WPFToolBarExample.View;
using WPFToolBarExample.ViewModel;

namespace WPFToolBarExample.Model
{
  public class CourseModel : BaseViewModel
  {
    #region Private Member Variables

    private string _courseName = string.Empty;
    private string _points = string.Empty;
    private ICommand _closeCommand;

    #endregion

    #region Public Properties

    public NewCourseView View { get; set; }

    public string CourseName
    {
      get { return _courseName; }
      set
      {
        _courseName = value;
        OnPropertyChanged(() => this.CourseName);
      }
    }

    public string Points
    {
      get { return _points; }
      set
      {
        _points = value;
        OnPropertyChanged(() => this.Points);
      }
    }

    public ICommand CloseCommand
    {
      get
      {
        if (_closeCommand == null)
          _closeCommand = new RelayCommand(param => CloseCommand_Execute(param), param => CloseCommand_CanExcute(param));

        return _closeCommand;
      }

    }

    private void CloseCommand_Execute(object param)
    {
      this.View.Close();
    }

    private bool CloseCommand_CanExcute(object param)
    {
      return true;
    }

    #endregion


    internal void ShowDialog()
    {
      View.ShowDialog();
    }


    public override void Save()
    {
      base.Save();

      MessageBox.Show( "Saving Course : " + this.CourseName, "Save Course", MessageBoxButton.OK,
        MessageBoxImage.Information);
    }
  }
}
